package com.atguigu.springcloud.config;

import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @USER: dayu
 * @DATE: 2020/3/30
 * @DESCRIPTION: 代码注入方式自定义网关
 */
@Configuration
public class GateWayConfig {

    @Bean
    public RouteLocator route(RouteLocatorBuilder routeLocatorBuilder){
        //id唯一需要自定义，patterns为路径，uri为路由的地址
        return routeLocatorBuilder.routes()
                .route("my_route2",r->r.path("/explore/**").uri("https://gitee.com/explore"))
                .route("my_route2",r->r.path("/s/**").uri("http://baijiahao.baidu.com/s"))
                .build();
    }
}
